#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#include<iostream>

#define SIZE  1024

int main(int argc,char*argv[])
{

    if(argc<3)
    {
        perror("列表参数不够\n");
        return -1;
    }

    const char *file1 = argv[1];
    const char *file2 = argv[2];
    int fd1 = open(file1, O_CREAT|O_RDWR);
    int fd2 = open(file2,O_CREAT|O_RDWR);

    if(fd1 == -1)
    {
        perror("文件1打开错误");
        return -1;
    }

    if(fd2 == -1)
    {
        perror("文件2打开错误");
        return -1;
    }

    char *buffer1[SIZE],buffer2[SIZE];
    memset(buffer1, 0, SIZE);
    memset(buffer2, 0, SIZE);
    int ret1 = read(fd1, buffer1, SIZE);
    int ret2 = read(fd2, buffer2, SIZE);
    if (ret1 == -1)
    {
        perror("文件1读取错误");
       return -1;
    }

    if (ret2 == -1)
    {
        perror("文件2读取错误");
       return -1;
    }

    ret1 = write(fd1,buffer2,sizeof(buffer2));
    ret2 = write(fd2, buffer1, sizeof(buffer1));
    if (ret1 == -1)
    {
        perror("文件1写入错误");
       return -1;
    }

    if (ret2 == -1)
    {
        perror("文件2写入错误");
       return -1;
    }

    ret1 = close(fd1);
    ret2 = close(fd2);
    if (ret1 == -1)
    {
        perror("文件1关闭错误");
       return -1;
    }

    if (ret2 == -1)
    {
        perror("文件2关闭错误");
       return -1;
    }

    return 0;
}